package com.yks.hbo.amazon.service.impl;


import com.yks.hbo.amazon.service.IPlsAmazonAdAccTokenService;
import com.yks.hbo.amazon.util.AmazonAdvertisingApiConstant;
import com.yks.hbo.amazon.util.PlsPropertiesUtil;
import com.yks.hbo.amazon.util.VoHelper;
import com.yks.hbo.amazon.vo.ResultVO;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: Amazon广告账号授权ServiceImpl
 * @Author: gaoliangyou
 * @Date: 2020/12/7 9:07
 */
@Service
public class PlsAmazonAdAccTokenServiceImpl implements IPlsAmazonAdAccTokenService {

    @Override
    public ResultVO advertisingOauth(String region) {
        String url;
        String redirectUri;
        switch (region) {
            case "NA":
                //url = "https://www.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.4e0ef2715b744ffe87b58c1192eb96fb&scope=advertising::campaign_management&response_type=code&redirect_uri=https://test.ykspls-http.kokoerp.com/api/amazon_ad/oauthReturn?region=NA";
                url = AmazonAdvertisingApiConstant.NaUrlPathPrefix.NA_AUTH_CODE_URL;
                redirectUri = PlsPropertiesUtil.getProperty("amazon.advertising.redirect.uri.na");
                break;
            case "EU":
                //url = "https://eu.account.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.4e0ef2715b744ffe87b58c1192eb96fb&scope=advertising::campaign_management&response_type=code&redirect_uri=https://test.ykspls-http.kokoerp.com/api/amazon_ad/oauthReturn?region=EU";
                url = AmazonAdvertisingApiConstant.EuUrlPathPrefix.EU_AUTH_CODE_URL;
                redirectUri = PlsPropertiesUtil.getProperty("amazon.advertising.redirect.uri.eu");
                break;
            case "FE":
                //url = "https://apac.account.amazon.com/ap/oa?client_id=amzn1.application-oa2-client.4e0ef2715b744ffe87b58c1192eb96fb&scope=advertising::campaign_management&response_type=code&redirect_uri=https://test.ykspls-http.kokoerp.com/api/amazon_ad/oauthReturn?region=FE";
                url = AmazonAdvertisingApiConstant.FeUrlPathPrefix.FE_AUTH_CODE_URL;
                redirectUri = PlsPropertiesUtil.getProperty("amazon.advertising.redirect.uri.fe");
                break;
            default:
                return VoHelper.getErrorResult("地区不存在");
        }
        url = url + "?client_id=" + AmazonAdvertisingApiConstant.App.CLIENT_ID + "&scope=advertising::campaign_management&response_type=code&redirect_uri=" + redirectUri;
        Map<String, String> map = new HashMap<String, String>(2);
        map.put("url", url);
        return VoHelper.getSuccessResult(map);
    }
}
